@extends('layouts.application')

@section('content')
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">奖项列表</strong> /
                    <small>Trophy List</small>
                </div>
            </div>

            <hr>
            @include('layouts.shared._flash')

            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a href="{{route('wechat.draw.create')}}" class="am-btn am-btn-default"><span
                                        class="am-icon-plus"></span> 新增
                            </a>
                        </div>
                    </div>
                </div>
                <div class="am-u-sm-12 am-u-md-3">
                    <form action="" method="get">
                        <div class="am-input-group am-input-group-sm">
                            <input type="text" name="keyword" value="{{Request::input('keyword')}}" class="am-form-field">
                            <span class="am-input-group-btn">
                            <button class="am-btn am-btn-default" type="submit">搜索</button>
                            <a href="{{route('wechat.draw.index')}}" class="am-btn am-btn-default">重置</a>
                        </span>
                        </div>
                    </form>
                </div>
            </div>

            <div class="am-g">
                <div class="am-u-sm-8">
                    <form class="am-form">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th class="table-id">ID</th>
                                <th class="table-title">奖项名称</th>
                                <th class="table-title">中奖概率</th>
                                <th class="table-title">奖品</th>
                                <th class="table-set">操作</th>
                            </tr>
                            </thead>
                            <tbody>

                            @foreach($draws as $draw)
                                <tr data-id="{{$draw->id}}">
                                    <td>{{$draw->id}}</td>
                                    <td>{{$draw->name}}</td>
                                    <td>{{$draw->weight}}</td>
                                    <td>{{$draw->prize}}</td>
                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <a href="{{route('wechat.draw.edit',$draw->id)}}"
                                                   class="am-btn am-btn-default am-btn-xs am-text-secondary"><span
                                                            class="am-icon-pencil-square-o"></span> 编辑
                                                </a>
                                                <button class="destroy am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only">
                                                    <span class="am-icon-trash-o"></span> 删除
                                                </button>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach

                            </tbody>
                        </table>

                    </form>
                </div>

            </div>
        </div>

        <footer class="admin-content-footer">
            <hr>
            <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
        </footer>

    </div>
@endsection

@section('js')
    <script>
        $(function () {
            //单个删除
            $('.destroy').click(function () {
                var id = $(this).parents('tr').data('id');
                var _this = $(this);

                $.ajax({
                    type: 'DELETE',
                    url: '/admin/wechat/draw/' + id,
                    data: {id: id},
                    success: function () {
                        _this.parents('tr').fadeOut(400);
                    }
                })
                return false;
            })

        })
    </script>
@endsection